package br.great.DAO;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* PhotoMap
* Copyright (c) 2007-2008 STEAMER - LIG, All rights reserved.
*/

/**
 * @author Developpement of PhotoMap
 */
public class DAO_InvertedIndexHasPhoto {

    int i;
    private PreparedStatement insertStatement;
    private static volatile DAO_InvertedIndexHasPhoto instanceInvertedIndexHasPhoto = new DAO_InvertedIndexHasPhoto();
    
    /** The private constructor of DAO_InvertedIndexHasPhoto for singleton
    */
    private DAO_InvertedIndexHasPhoto(){
     try {
            PgConnect conn = PgConnect.getInstance();
            insertStatement = conn.executeInsertWithPreparedStatement(getInsertStatement());
        } catch (Exception ex) {
            System.err.println("Problems to prepare statement");
        }
    }
    public String getInsertStatement(){
        String insertTuple= "INSERT INTO INVERTED_INDEX_has_PHOTO values(?,?,?);";
        return  insertTuple; 
    }
    /** The method for get the instance of the class DAO_InvertedIndexHasPhoto
    * @return DAO_InvertedIndexHasPhoto instaceDAO_InvertedIndexHasPhoto
    */
    public static DAO_InvertedIndexHasPhoto getInstance() {
        //if(instaceDAO_InvertedIndexHasPhoto==null)
           synchronized(DAO_InvertedIndexHasPhoto.class) {
             if (instanceInvertedIndexHasPhoto == null)
               instanceInvertedIndexHasPhoto = new DAO_InvertedIndexHasPhoto();
           }
        return instanceInvertedIndexHasPhoto;
    }
    
    public void insertInvertedIndexPhoto(int idTag, int idMultimedia, double weight){
        try {
            
              insertStatement.setInt(1, idTag);
              insertStatement.setInt(2, idMultimedia);
              insertStatement.setDouble(3,weight);
              insertStatement.execute();
//           
           // String insertInvertedIndexHasPhoto = "INSERT INTO INVERTED_INDEX_has_PHOTO values("+idTag+","+idMultimedia+","+weight+");";

            /*
            PgConnect conn = PgConnect.getInstance();
//              conn.executeInsert(insertInvertedIndexHasPhoto);

           
            conn.Close();*/
        } catch (Exception ex) {
            //Logger.getLogger(DAO_InvertedIndexHasPhoto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void main(String[] args){
        DAO_InvertedIndexHasPhoto dchca = DAO_InvertedIndexHasPhoto.getInstance();
        dchca.insertInvertedIndexPhoto(759, 2, 1.5);
    }

}
